package com.itheima.mapper;

import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {
    /**
     * 查询员工总数
     * @return
     */
    @Select("select count(*) from tlias.emp")
    public Integer count();

    /**
     * 分页查询员工信息
     * @param start 起始索引
     * @param pageSize 查询记录数
     * @return
     */
    @Select("select * from tlias.emp limit #{start}, #{pageSize}")
    public List<Emp> page(@Param("start") Integer start, @Param("pageSize") Integer pageSize);

    /**
     * 条件分页查询
     * @param name
     * @param gender
     * @param begin
     * @param end
     * @return
     */
    public List<Emp> list(@Param("name") String name,@Param("gender") Short gender,
                          @Param("begin") LocalDate begin,@Param("end") LocalDate end);

    /**
     * 删除员工信息
     * @param ids
     */
    void delete(@Param("ids") List ids);

    /**
     * 新增员工信息
     * @param emp
     */
    @Insert("insert into tlias.emp(username, name, gender, image, job, entrydate, " +
            "dept_id, create_time, update_time)" +
            " values( #{username}, #{name}, #{gender}, #{image}, " +
            "#{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime}) ")
    void add(Emp emp);

    /**
     * 查询回显
     * @param id
     * @return
     */
    @Select("select * from tlias.emp where id = #{id}")
    Emp select(Integer id);

    /**
     * 修改员工信息
     * @param emp
     */
//    @Update("update tlias.emp set username = #{username}, name = #{name}, gender = #{gender}," +
//            "image = #{image}, job = #{job}, entrydate = #{entrydate}, dept_id = #{deptId}," +
//            "update_time = #{updateTime} where id = #{id}")
    void update(Emp emp);

    /**
     * 登录操作（查询员工表中是否含有对应的用户名和密码）
     * @param emp
     * @return
     */
    @Select("select * from tlias.emp where username = #{username} and password = #{password}")
    Emp login(Emp emp);

    /**
     * 根据部门id删除员工信息
     * @param deptId
     */
    @Delete("delete from tlias.emp where dept_id = #{deptId}")
    void deleteByDeptId(Integer deptId);
}
